<?php
/**
 * 推广链接
 */
namespace App;
use Model\LinkMod;

defined('IN_IA') or exit('Access Denied');

class Link extends Action
{
    private $Link = null;

    private $_link_id = 0;
    public function __construct()
    {
        parent::__construct();
        $this->Link = new LinkMod();
        $this->getUid();
        if(isset($this->_gpc["link_id"])) $this->_link_id = $this->_gpc["link_id"];
    }

    /**
     * 添加推广链接
     * @param data 添加的数据
     */
    public function add()
    {
        $this->_gpc["data"]["uniacid"] = $this->_uniacid;
        $this->_gpc["data"]["uid"] = $this->_uid;
        if($this->Link->insert($this->_gpc["data"])){
            $this->_result = array("status"=>"success","data"=>pdo_insertid());
        }
        $this->result($this->_result);
    }

    /**
     * 获取指定用户的推广链接
     * @param uid 用户id
     * @param limit 请求下标
     */
    public function getList()
    {
        $_list = $this->Link->findAll(
            array(
                "uniacid"=>$this->_uniacid,
                "uid"=>$this->_uid
            ),
            array(
                "order"=>array("id","desc"),
                "limit"=>$this->_gpc["limit"]
            ),
            array("id","name","link")
        );
        if(count($_list) > 0){
            $this->_result = array("status"=>"success","data"=>$_list);
        }
        $this->result($this->_result);
    }

    /**
     * 删除链接
     * @param link_id id
     */
    public function delete()
    {
        if($this->Link->delete(array("id"=>$this->_link_id))){
            $this->_result = array("status"=>"success");
        }
        $this->result($this->_result);
    }

}